package com.wen.wencglib;

import java.util.LinkedList;
import java.util.Queue;

/**
 * @author wenl
 * @version V2.0
 * @project education
 * @package com.wen.wencglib
 * @date 2020/4/2
 * @describe
 */
public class Java8Test {

    Queue<String> queue = new LinkedList<>();

    public static void main(String[] args) throws InterruptedException {

        Java8Test ja = new Java8Test();

        ja.addTask("java");
        ja.addTask("java1");
        ja.addTask("java2");
        System.out.println(ja.getTask());
    }

    public  void addTask(String s) {
        this.queue.add(s);
        this.notify();
    }

    public synchronized String getTask() throws InterruptedException {
        System.out.println("get start...");
        while (queue.isEmpty()) {
            this.wait();
        }

        System.out.println("get end.");
        return queue.remove();
    }

}
